#include <iostream>
#include <algorithm>
#include "Student.h"

using namespace std;

void selectionSort1(int arr[], int n) {
    for (int i = 0; i < n; ++i) {
        int index = i;
        for (int j = i+1; j < n; ++j) {
            if (arr[index] > arr[j])
                index = j;
        }

        swap(arr[i], arr[index]);
    }
}

void selectionSort2(int arr[], int n) {
    for (int i = 0; i < n; ++i) {
        int index = i;
        for (int j = i+1; j < n; ++j) {
            if (arr[index] > arr[j])
                index = j;
        }

        swap(arr[i], arr[index]);
    }
}

template <typename T>
void selectionSort(T arr[], int n) {
    for (int i = 0; i < n; ++i) {
        //寻找[ｉ，n)区间里的最小值
        int minIndex = i;
        for (int j = i; j < n; ++j) {
            if (arr[j] < arr[minIndex])
                minIndex = j;
        }

        swap(arr[i], arr[minIndex]);
    }
}

int main() {
    int arr[10] = {10,9,8,7,6,5,4,3,2,1};
    selectionSort(arr, 10);
    for (int i = 0; i < 10; ++i) {
        std::cout << arr[i] << " ";
    }
    cout<<endl;

    float arr1[4] = {1.1,2.2,3.3,4.4};
    selectionSort(arr1, 4);
    for (int i = 0; i < 4; ++i) {
        std::cout<< arr[i] << " ";
    }
    cout<<endl;

    string c[4] = {"D","B","C","A"};
    selectionSort(c, 4);
    for (int j = 0; j < 4; ++j) {
        std::cout << c[j] << " ";
    }
    cout<<endl;

    Student d[4] = { {"D", 100}, {"T", 80}, {"G", 20}, {"E", 98} };
    selectionSort(d, 4);
    for (int k = 0; k < 4; ++k) {
        std::cout<<d[k]<<" ";
    }
    cout<<endl;

    return 0;
}